package controller;

import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.subject.Subject;

@Path(value = "/admin",viewPath = "/pages")
public class AdminController extends Controller {

    @RequiresAuthentication
    public void index(){
        render("index.html");
    }

    public void login(){
        render("login/login.html");
    }

    public void logout(){
        SecurityUtils.getSubject().logout();
        redirect("/");
    }

    public void sinup(){
        String username=get("username");
        String password=get("password");
        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
        SecurityUtils.getSubject().login(token);
        setAttr("erro",0);
        renderJson();
    }
}
